var fs = require('fs');
var Q = require('q');
var colors = require('colors');

var targetFile = "./test2.js";
var encoding = "utf8";
var handler = {
		success: function(result) {
			console.log('ok'.green);
			console.log(result.blue);
		},
		fail: function(error) {
			console.log('fail'.red);
		}
	}
	//nfcall
if (false) {
	var fsReadFile = Q.nfcall(fs.readFile, targetFile, encoding);
	fsReadFile.then(handler.success, handler.fail);
}

// defer
if (true) {
	var fsReadFile_deferd = function(file, encoding) {
		var defer = Q.defer();
		fs.readFile(file, encoding, function(error, result) {
			if (error) {
				defer.reject(error);
			} else {
				defer.resolve(result);
			}
		});
		return defer.promise;
	}

	//
	fsReadFile_deferd(targetFile, encoding).then(handler.success, handler.fail);
}